package com.google.code.springbreeze.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.google.code.springbreeze.dao.AccountMapper;
import com.google.code.springbreeze.entity.Account;
import com.google.code.springbreeze.entity.Page;

@Service
public class AccountService {

  @Autowired
  private AccountMapper accountMapper;

  public List<Account> getAllAccount(Page page) {
	 page.setCount(accountMapper.getAllAccountCount());
	 return accountMapper.getAllAccount(page);
  }
  
  public Account getAccountByUserID(String userid) {
    return accountMapper.getAccountByUserID(userid);
  }
  
  public Account getAccount(String username, String password) {
    Account account = new Account();
    account.setPassword(password);
    return accountMapper.getAccountByUsernameAndPassword(account);
  }

  public void insertAccount(Account account) {
    accountMapper.insertAccount(account);
  }

  @Transactional
  public int updateAccount(Account account) {
	return accountMapper.updateAccount(account);
  }
  
  public int deleteAccountByUserID(String userid) {
	  return accountMapper.deleteAccountByUserID(userid);
  }

}
